//=============================================================================
//
//   Copyright (C) 2020 All rights reserved.
//
//   Filename:		mod.rs
//
//   Author: Wang Zhecheng - wangzhecheng@yeah.net
//
//   Date: 2020-10-28 06:57
//
//   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
//
//   Last modified:	2020-10-29 23:31
//
//   Description:
//
//=============================================================================
pub mod displace;
pub mod pore;

use crate::component::node::Node;
use crate::dimension::DimType;
use crate::method::unknowns::{displace::DisplaceUnknwon, pore::PoreUnknwon};

pub trait UnknownType<DT: DimType> {
    fn set_nodal_dofs(&self, node: &mut Node<DT>);
}

#[derive(Debug)]
pub enum Unknown<DT: DimType> {
    Displace(DisplaceUnknwon<DT>),
    Pore(PoreUnknwon<DT>),
    None,
}

impl<DT: DimType> UnknownType<DT> for Unknown<DT> {
    fn set_nodal_dofs(&self, node: &mut Node<DT>) {
        match &self {
            &Unknown::Displace(disp) => disp.set_nodal_dofs(node),
            &Unknown::Pore(pore) => pore.set_nodal_dofs(node),
            &Unknown::None => panic!("Empty unknown type"),
        }
    }
}

pub fn build_unknown<DT: DimType>(name: &str) -> Box<dyn UnknownType<DT>> {
    match name.to_lowercase().as_str() {
        "displace" => Box::new(DisplaceUnknwon::<DT>::default()),
        "pore" => Box::new(PoreUnknwon::<DT>::default()),
        _ => panic!("Invalid unknown type {}", name),
    }
}
